<%
' convert to sql competible string
Function toSQLVal(d)
	If d <> "" Then
		toSQLVal = Replace(d, "'", "''")
	End if
End Function

'Function to safty Convert Long Number
Private Function toLng(ByVal val)
	
	'Initialize to Return 0
	toLng = 0
	
	'Check before convert to Long 
	If IsNumeric(val) Then
		toLng = CLng(val)
	End If
	
End Function

'*******************************************
'***			File upload 			****
'*******************************************
'Function to check file existence
Private dirDownload
dirDownload = Server.MapPath("downloads") & "\"
Function fileExists(path)
	
	Dim oFS', oFile
	
	fileExists = False	
	Set oFS = Server.CreateObject("Scripting.FileSystemObject")	
	If oFS.FileExists(path) Then
'		Set oFile = oFS.GetFile(path)
'		fileExists = oFile.Size
		fileExists = True
	End if
	
	Set oFS = Nothing
'	Set oFile = Nothing
	
End Function

'*********************************************
'***	Move File
'*********************************************
' Procedure name	: MoveFile
' Argument 			:	fSrc = File source
'						fDest = File destination
' Action			: Physically move file
' Return			: Not return 
Private Sub MoveFile(ByVal fSrc, ByVal fDest)
	Dim oFS
	
	If Not (LCase(Mid(fSrc, 1, InStrRev(fSrc,"\")))=LCase(fDest)) Then
		Set oFS = Server.CreateObject("Scripting.FileSystemObject")
		
		If Not oFS.FolderExists(fDest) Then
			oFS.CreateFolder(fDest)
		End if
		' Move File
		If oFS.FileExists(fSrc) Then
			oFS.MoveFile fSrc, fDest			
		End if
		' Clean up
		Set oFS = Nothing
	End if
End Sub

'*********************************************
'***	RenameFolder
'*********************************************
' Procedure name	: RenameFolder
' Argument 			:	fSrc = File source
'						newName = New File name
' Action			: Physically rename a folder
' Return			: Not return 
Private Sub RenameFolder(ByVal fSrc, ByVal newName)
	Dim oFS, oFld
	
	Set oFS = Server.CreateObject("Scripting.FileSystemObject")
	
	' Rename
	'Response.Write(newName): response.End()
	If oFS.FolderExists(fSrc) Then
		Set oFld = oFS.GetFolder(fSrc)
		oFld.Name = newName
	End if
	' Clean up
	Set oFld = Nothing
	Set oFS = Nothing
End Sub

'*********************************************
'***	DelFolder
'*********************************************
' Procedure name	: DelFolder
' Argument 			:	fName = Folder name
' Action			: Physically delete a folder
' Return			: Not return 
Private Sub DelFolder(ByVal fld)
	Dim oFS
	
	Set oFS = Server.CreateObject("Scripting.FileSystemObject")
	
	' Rename
	If oFS.FolderExists(fld) Then
		oFS.DeleteFolder fld
	End if
	' Clean up
	Set oFS = Nothing
End Sub


' Function safeFilename
' convert to a safe filename for window
' Input:	- n		: name to convert
' InvalidChars for window: / \ : * ? < > |
' InvalidChars for web:	# Space
' InvalidChars for mappath: ,
' Output:	safe filename
Private Const InvalidChars = "/;\;:;*;?;<;>;|;#; ;,"
Function safeFilename(ByVal n)
	Dim arChars, i
	
	arChars = Split(InvalidChars, ";")
	For i=0 to UBound(arChars)
		n = Replace(n, arChars(i), "_")
	Next
	safeFilename = n
End Function


' Function dropboxDate
' to convert date to (dd-mmm-yy) format 
Function dropboxDate(ByVal v)
	Dim d, m, y, sep
	
	sep = "-"
	If IsDate(v) Then
		d = zeroPad(Day(v))
		m = Month(v)
		m = Left(MonthName(m), 3)
		y = Right(Year(v), 2)
		dropboxDate =  d & sep & m & sep & y 
	End if
End function

' Function leftPad
' Text padding
Function zeroPad(v)
	zeroPad = v
	If v < 10 Then
		zeroPad = "0" & v
	End if
End function



'******************************************
'***  	Function to trim strings	***
'******************************************

'Function to chop down the length of a string and add '...'
Private Function TrimString(ByVal strInputString, intStringLength)
	
	Dim strTempInput
	Dim intTrimLentgh
	Dim intPrevTrim, intNextTrim

	'Trim the string down
	strTempInput = strInputString
	strInputString = Trim(strInputString) & " "

	'If the length of the text is longer than the max then cut it and place '...' at the end
	If CLng(Len(strInputString)) > intStringLength Then
		
		'Get the part in the string to trim it from
		intNextTrim = InStr(intStringLength, strInputString, " ", vbTextCompare)
		intPrevTrim = InStrRev(strInputString, " ", intStringLength, vbTextCompare)
		
'		intTrimLentgh = InStr(intStringLength, strInputString, " ", vbTextCompare)
		
		If intStringLength-intPrevTrim < intNextTrim-intStringLength Then
			strInputString = Mid(strInputString, 1, intPrevTrim)
		Else
			strInputString = Mid(strInputString, 1, intNextTrim)
		End if
		
		'Make sure the user hasn't entered a long line of text with no break (most words won't be over a haft of trim len chars
		If CLng(Len(strInputString)) => intStringLength + intStringLength\4 Then
			strInputString = Mid(Trim(strTempInput), 1, intPrevTrim)
		End If
		
		'Trim to for 0 length
		If strInputString="" Then
			strInputString = Mid(Trim(strTempInput), 1, intStringLength)
		End if

		'Place '...' at the end
		strInputString = Trim(strInputString)
		If Not(strTempInput = strInputString) Then _
		 	strInputString = strInputString & "..."
	End If
	
	'Return string
	TrimString = strInputString 
End Function

%>